export function createElement(name: string, attr: {[key: string]: string}| string = {}):HTMLElement {
    let ele: HTMLElement = document.createElement(name);
    if(typeof attr == 'string') {
        ele.setAttribute('class', attr);
    } else {
        for(let key in <{[key: string]: string}>attr) {
            try {
                ele.setAttribute(key, (<{[key: string]: string}>attr)[key]);
            } catch (error) {
                console.warn(`can't set attribute ${key}`);
            }
        }        
    }
    return ele;
} 
export function insertAfter(newElement: HTMLElement,targetElement: HTMLElement){
    var parent = targetElement.parentNode;
    if(parent.lastChild == targetElement){
        parent.appendChild(newElement);
    } else {
        parent.insertBefore(newElement,targetElement.nextSibling);
    }
}